home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 2.6 KB | 96 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // Restricted Rights Legend
- // Use, duplication, or disclosure is subject to restrictions as set forth
- // in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer
- // Software clause at DFARS 252.227-7013.
- //
- // BCSearcL.cpp
- //
- // This file contains the definitions for the list searching tools.
-
- #include "BCSearcL.h"
-
- template<class Item, class List>
- BC_TListSearch<Item, List>::BC_TListSearch()
- : fIsEqual(0) {}
-
- template<class Item, class List>
- BC_TListSearch<Item, List>::
- BC_TListSearch(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
- : fIsEqual(IsEqual) {}
-
- template<class Item, class List>
- BC_TListSearch<Item, List>::~BC_TListSearch() {}
-
- template<class Item, class List>
- void BC_TListSearch<Item, List>::
- SetIsEqualFunction(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
- {
- fIsEqual = IsEqual;
- }
-
- template<class Item, class List>
- BC_TSequentialListSearch<Item, List>::BC_TSequentialListSearch() {}
-
- template<class Item, class List>
- BC_TSequentialListSearch<Item, List>::
- BC_TSequentialListSearch(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
- : BC_TListSearch<Item, List>(IsEqual) {}
-
- template<class Item, class List>
- BC_TSequentialListSearch<Item, List>::~BC_TSequentialListSearch() {}
-
- template<class Item, class List>
- List BC_TSequentialListSearch<Item, List>::Location(const List& target, const Item& key)
- {
- List l(target);
- while (!l.IsNull()) {
- if (fIsEqual(l.Head(), key))
- return l;
- l.Tail();
- }
- l.Clear();
- return l;
- }
-
- template<class Item, class List>
- BC_TOrderedListSearch<Item, List>::BC_TOrderedListSearch()
- : fIsLessThan(0) {}
-
- template<class Item, class List>
- BC_TOrderedListSearch<Item, List>::BC_TOrderedListSearch
- (BC_Boolean (*IsEqual)(const Item& x, const Item& y),
- BC_Boolean (*IsLessThan)(const Item& x, const Item& y))
- : BC_TListSearch<Item, List>(IsEqual),
- fIsLessThan(IsLessThan) {}
-
- template<class Item, class List>
- BC_TOrderedListSearch<Item, List>::~BC_TOrderedListSearch() {}
-
- template<class Item, class List>
- void BC_TOrderedListSearch<Item, List>::
- SetIsLessThanFunction(BC_Boolean (*IsLessThan)(const Item& x, const Item& y))
- {
- fIsLessThan = IsLessThan;
- }
-
- template<class Item, class List>
- List BC_TOrderedListSearch<Item, List>::
- Location(const List& target, const Item& key)
- {
- List l(target);
- while (!l.IsNull()) {
- if (fIsEqual(l.Head(), key))
- return l;
- if (fIsLessThan(key, l.Head())) {
- l.Clear();
- return l;
- }
- l.Tail();
- }
- l.Clear();
- return l;
- }
-